package com.sduept.nwld.dataserver.controller.equipment.assessment;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import com.sduept.bigdata.equipment.assessment.enums.ItemTypeEnum;
import com.sduept.bigdata.equipment.assessment.model.inspection.InspectionItem;
import com.sduept.bigdata.equipment.assessment.model.inspection.InspectionQuestionEquipment;
import com.sduept.bigdata.equipment.assessment.model.inspection.InspectionQuestionEquipmentFeedback;

/**
 * 变电站评价详情table展示编辑模型
 * @author pengz
 *
 */
public class InspStationTableModel {		
	private String id;
	/**
	 * 是否保存
	 */
	private boolean save;
	
	private String planId;
	
	private String projectId;
	private String projectNo; // 模块，一、二
	private String projectName; // 模块名称，基础管理、保护及二次回路
	private int projectOrder;
	
	private String itemId;
	private String itemNo; // 序号,1.1,1.2,1.3...
	private String itemName; // 评价项目
	private int itemOrder;
	//原风险等级
	private String riskLevel;
	//风险等级触发升级条件后的等级
	private String riskLevelRefer;	 
	
	private String inspectionId;
	private String inspectionNo;
	private String inspectionName; // 检查要素及要求
	private int inspectionOrder;
	
	private String scoreNo;// 评分标准序号
	private String scoreName; // 评分标准名称
	private int scoreOrder;
	private int status;
	
	private String docName; // 检查参照依据
	
	//扣分上限
	private float deductionCeiling;
	//扣分标准
	private float deductionCriteria;
	/**
	 * InspectionItem中类型为INSPECTIONCRITERION（评分标准）的id
	 */
	private String inspectionItemId;

	//扣分
	private float deduct;
	//问题描述
	private String problemDescription;
	/**
	 * 评分的专家id(记录最后一次评分的专家）
	 */
	private String expertId;

	/**
	 * 评分的专家名称
	 */
	private String expertName;

	private List<InspectionQuestionEquipment> questionEquipments;
	
	/**
	 * 类型为INSPECTIONREQUIREMENT的评价标准的扣分上限
	 */
	private float inspectiontDeductionCeiling;
	/**
	 * 检查要素及要求的扣分值
	 */
	private float requirementDeduct;
	/**
	 * 类型为INSPECTIONITME的评价标准的扣分上限
	 */
	private float itemDeductionCeiling;
	/**
	 * 类型为INSPECTIONPROJECT的评价标准的扣分上限
	 */
	private float projectDeductionCeiling;
	
	/**
	 * 整改建议
	 */
	private String recommendation;
	/**
	 * 被检单位反馈意见
	 */
    private String feedback;
		
	public InspStationTableModel(InspectionItem item) {
		this.id = item.getId();
		if(item.getQuestionEquipments()!=null&&!item.getQuestionEquipments().isEmpty()) {
			this.questionEquipments = item.getQuestionEquipments();
		}else {
			this.questionEquipments = new ArrayList<InspectionQuestionEquipment>();
		}
		genItem(item);
	}
	public InspStationTableModel(InspectionItem item,
			InspectionQuestionEquipmentFeedback feedback) {
		this.id = item.getId();
		if(item.getQuestionEquipments()!=null&&!item.getQuestionEquipments().isEmpty()) {
			this.questionEquipments = item.getQuestionEquipments();
		}else {
			this.questionEquipments = new ArrayList<InspectionQuestionEquipment>();
		}
		if(feedback!=null) {
			this.feedback = feedback.getFeedback();
		}
		genItem(item);
	}
	private void genItem(InspectionItem item) {
		if(item != null) {
			switch (item.getItemType()) {
			case INSPECTIONPROJECT://检查大项
				projectId = item.getId();
				projectNo = item.getNodeNo();
				projectName = item.getContent();
				projectOrder = item.getNodeOrder();
				projectDeductionCeiling = item.getDeductionCeiling();				
				break;
			case INSPECTIONITME://检查项目
				itemId = item.getId();
				itemNo = item.getNodeNo();
				itemName = item.getContent();
				itemOrder = item.getNodeOrder();
				itemDeductionCeiling = item.getDeductionCeiling();
				break;
			case INSPECTIONREQUIREMENT://检查要素及要求
				inspectionId = item.getId();
				inspectionNo = item.getNodeNo();
				inspectionName = item.getContent();
				inspectionOrder = item.getNodeOrder();
				inspectiontDeductionCeiling = item.getDeductionCeiling();
				requirementDeduct = item.getDeduct();
				riskLevel=item.getRealRiskLevel();
				riskLevelRefer=item.getRiskLevelRefer();
				break;				
			case INSPECTIONCRITERION://检查标准
				scoreNo = item.getNodeNo();
				scoreName = item.getContent();
				scoreOrder = item.getNodeOrder();					
				status = item.getStatus();
				inspectionItemId = item.getId();
				problemDescription = item.getProblemDescription();
				//扣分上限
				deductionCeiling = item.getDeductionCeiling();
				//扣分标准
				deductionCriteria = item.getDeductionCriteria();
				//扣分实际值
				deduct = item.getDeduct();
				planId=item.getPlanId();
				expertId = item.getActualAssessmentExpertId();
				expertName = item.getActualAssessmentExpertName();
				
				recommendation = item.getRecommendation();
				break;				
			default:
				break;
			}
			if(item.getParent() != null) 
				genItem(item.getParent());
		}
	}
	public static List<InspStationTableModel> getListByInspectionCriterions(List<InspectionItem> inspectionCriterions) {		
		List<InspStationTableModel> modelList = new ArrayList<InspStationTableModel>();
		//评价项目
		for (InspectionItem insItem : inspectionCriterions) {
			if(insItem.getItemType() == ItemTypeEnum.INSPECTIONCRITERION)
				modelList.add(new InspStationTableModel(insItem));
		}
		return modelList;
	}
	public static List<InspStationTableModel> getListByInspectionCriterionAndFeedbackMap(
			Map<InspectionItem, InspectionQuestionEquipmentFeedback> itemAndFeedbackMap) {
		List<InspStationTableModel> modelList = new ArrayList<InspStationTableModel>();
		//评价项目
		for (InspectionItem insItem : itemAndFeedbackMap.keySet()) {
			if(insItem.getItemType() == ItemTypeEnum.INSPECTIONCRITERION)
				modelList.add(new InspStationTableModel(insItem,itemAndFeedbackMap.get(insItem)));
		}
		return modelList;
	}
	/**
	 * 排序，顺序为：projectOrder，itemOrder，inspectionOrder，scoreOrder
	 */
	public static void sortModelList(List<InspStationTableModel> selectLists) {
		selectLists.sort(Comparator.comparingInt(InspStationTableModel::getProjectOrder)
				.thenComparingInt(InspStationTableModel::getItemOrder)
				.thenComparingInt(InspStationTableModel::getInspectionOrder)
				.thenComparingInt(InspStationTableModel::getScoreOrder)
				);
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public boolean isSave() {
		return save;
	}
	public void setSave(boolean save) {
		this.save = save;
	}
	public String getProjectNo() {
		return projectNo;
	}
	public void setProjectNo(String projectNo) {
		this.projectNo = projectNo;
	}
	public String getProjectName() {
		return projectName;
	}
	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}
	public int getProjectOrder() {
		return projectOrder;
	}
	public void setProjectOrder(int projectOrder) {
		this.projectOrder = projectOrder;
	}
	public String getItemNo() {
		return itemNo;
	}
	public void setItemNo(String itemNo) {
		this.itemNo = itemNo;
	}
	public String getItemName() {
		return itemName;
	}
	public void setItemName(String itemName) {
		this.itemName = itemName;
	}
	public int getItemOrder() {
		return itemOrder;
	}
	public void setItemOrder(int itemOrder) {
		this.itemOrder = itemOrder;
	}
	public String getInspectionNo() {
		return inspectionNo;
	}
	public void setInspectionNo(String inspectionNo) {
		this.inspectionNo = inspectionNo;
	}
	public String getInspectionName() {
		return inspectionName;
	}
	public void setInspectionName(String inspectionName) {
		this.inspectionName = inspectionName;
	}
	public int getInspectionOrder() {
		return inspectionOrder;
	}
	public void setInspectionOrder(int inspectionOrder) {
		this.inspectionOrder = inspectionOrder;
	}
	public String getScoreNo() {
		return scoreNo;
	}
	public void setScoreNo(String scoreNo) {
		this.scoreNo = scoreNo;
	}
	public String getScoreName() {
		return scoreName;
	}
	public void setScoreName(String scoreName) {
		this.scoreName = scoreName;
	}
	public int getScoreOrder() {
		return scoreOrder;
	}
	public void setScoreOrder(int scoreOrder) {
		this.scoreOrder = scoreOrder;
	}
	public String getDocName() {
		return docName;
	}
	public void setDocName(String docName) {
		this.docName = docName;
	}
	public float getDeductionCeiling() {
		return deductionCeiling;
	}
	public void setDeductionCeiling(float deductionCeiling) {
		this.deductionCeiling = deductionCeiling;
	}
	public float getDeductionCriteria() {
		return deductionCriteria;
	}
	public void setDeductionCriteria(float deductionCriteria) {
		this.deductionCriteria = deductionCriteria;
	}
	
	public String getInspectionItemId() {
		return inspectionItemId;
	}
	public void setInspectionItemId(String inspectionItemId) {
		this.inspectionItemId = inspectionItemId;
	}
	public float getDeduct() {
		return deduct;
	}
	public void setDeduct(float deduct) {
		this.deduct = deduct;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getExpertId() {
		return expertId;
	}
	public void setExpertId(String expertId) {
		this.expertId = expertId;
	}
	public String getExpertName() {
		return expertName;
	}
	public void setExpertName(String expertName) {
		this.expertName = expertName;
	}
	public String getProjectId() {
		return projectId;
	}
	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}
	public String getItemId() {
		return itemId;
	}
	public void setItemId(String itemId) {
		this.itemId = itemId;
	}
	public String getInspectionId() {
		return inspectionId;
	}
	public void setInspectionId(String inspectionId) {
		this.inspectionId = inspectionId;
	}
	public float getInspectiontDeductionCeiling() {
		return inspectiontDeductionCeiling;
	}
	public void setInspectiontDeductionCeiling(float inspectiontDeductionCeiling) {
		this.inspectiontDeductionCeiling = inspectiontDeductionCeiling;
	}
	public float getItemDeductionCeiling() {
		return itemDeductionCeiling;
	}
	public void setItemDeductionCeiling(float itemDeductionCeiling) {
		this.itemDeductionCeiling = itemDeductionCeiling;
	}
	public float getProjectDeductionCeiling() {
		return projectDeductionCeiling;
	}
	public void setProjectDeductionCeiling(float projectDeductionCeiling) {
		this.projectDeductionCeiling = projectDeductionCeiling;
	}
	public List<InspectionQuestionEquipment> getQuestionEquipments() {
		return questionEquipments;
	}
	public void setQuestionEquipments(List<InspectionQuestionEquipment> questionEquipments) {
		this.questionEquipments = questionEquipments;
	}
	public String getRiskLevel() {
		return riskLevel;
	}
	public void setRiskLevel(String riskLevel) {
		this.riskLevel = riskLevel;
	}
	public String getRiskLevelRefer() {
		return riskLevelRefer;
	}
	public void setRiskLevelRefer(String riskLevelRefer) {
		this.riskLevelRefer = riskLevelRefer;
	}

	public String getPlanId() {
		return planId;
	}
	public void setPlanId(String planId) {
		this.planId = planId;
	}
	public float getRequirementDeduct() {
		return requirementDeduct;
	}
	public void setRequirementDeduct(float requirementDeduct) {
		this.requirementDeduct = requirementDeduct;
	}
	public String getRecommendation() {
		return recommendation;
	}
	public void setRecommendation(String recommendation) {
		this.recommendation = recommendation;
	}
	public String getFeedback() {
		return feedback;
	}
	public void setFeedback(String feedback) {
		this.feedback = feedback;
	}
	public String getProblemDescription() {
		return problemDescription;
	}
	public void setProblemDescription(String problemDescription) {
		this.problemDescription = problemDescription;
	}
	
	
}
